-
Notifications
You must be signed in to change notification settings - Fork 13.4k
[rustdoc] Give more information into extracted doctest information #141399
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
This comment has been minimized.
This comment has been minimized.
cd34db0
to
4e95830
Compare
Fixed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Core logic looks correct (mostly just exposing existing variables), just have a few nits about naming to hopefully increase readability.
src/librustdoc/doctest/make.rs
Outdated
let mut prog = String::new(); | ||
let everything_else = self.everything_else.trim(); | ||
let mut crate_level_code = String::new(); | ||
let code = self.everything_else.trim().to_string(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: could we call this inner_code
to disambiguate?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Disambiguate with which variable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test_code
. just looking at those two variable names it's not clear which is the unprocessed input.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see. Yeah good point. Gonna rename both.
4e95830
to
9888eb4
Compare
Updated. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks pretty good, I've just got a few more notes about naming, most of which are extrapolations of previous suggested changes.
let (wrapper, line_offset) = | ||
doctest.generate_unique_doctest(test_code, dont_insert_main, opts, crate_name); | ||
(code, line_offset) | ||
(wrapper.to_string(), line_offset) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: should s/wrapper/wrapped/, same reasoning as before.
let (wrapper, full_test_line_offset) = doctest.generate_unique_doctest( | ||
&scraped_test.text, | ||
scraped_test.langstr.test_harness, | ||
&global_opts, | ||
Some(&global_opts.crate_name), | ||
); | ||
let runnable_test = RunnableDocTest { | ||
full_test_code, | ||
full_test_code: wrapper.to_string(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: s/wrapper/wrapped/, same reasoning as before
@@ -42,7 +43,7 @@ impl ExtractedDocTests { | |||
.edition(edition) | |||
.lang_str(&langstr) | |||
.build(None); | |||
let (full_test_code, size) = doctest.generate_unique_doctest( | |||
let (wrapper, _size) = doctest.generate_unique_doctest( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let (wrapper, _size) = doctest.generate_unique_doctest( | |
let (wrapped, _size) = doctest.generate_unique_doctest( |
@@ -52,21 +53,46 @@ impl ExtractedDocTests { | |||
file: filename.prefer_remapped_unconditionaly().to_string(), | |||
line, | |||
doctest_attributes: langstr.into(), | |||
doctest_code: if size != 0 { Some(full_test_code) } else { None }, | |||
doctest_code: match wrapper { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doctest_code: match wrapper { | |
doctest_code: match wrapped { |
Valid { | ||
crate_level_code: String, | ||
wrapper: Option<WrapperInfo>, | ||
code: String, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure code
is descriptive enough. it doesn't make it clear whether it the original unprocessed code, the fully processed code, or something else. in reality what exactly it contains depends on if we added a main
function, so perhaps we could just add a doc comment to the field instead of trying to encapsulate all that complexity in a name.
If we do rename it, we should probably also rename any local variables whose name is derived from this due to the struct pattern sugar, such as in DocTestWrapResult::to_string
.
@@ -210,53 +277,53 @@ impl DocTestBuilder { | |||
/// lines before the test code begins. | |||
pub(crate) fn generate_unique_doctest( | |||
&self, | |||
test_code: &str, | |||
doctest_code: &str, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: in extracted.rs
, we use the name doctest_code
to refer to the fully processed code, while here we are using it to refer to the unprocessed source. this seems needlessly confusing.
Follow-up of #134531.
This update fragment the doctest code into its sub-parts to give more control to the end users on how they want to use it.
The new JSON looks like this:
for this doctest:
With this, I think it matches what you need @ojeda? If so, once merged I'll update the patch I sent to RfL.
r? @aDotInTheVoid